package com.linkhub.oms.dao.mpservice.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.linkhub.oms.dao.mapper.ProductStockEntityMapper;
import com.linkhub.oms.dao.mpservice.IProductStockService;
import com.linkhub.oms.entity.ProductStockEntity;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 本地商品库存表 服务实现类
 * </p>
 *
 * @author echo
 * @since 2024-04-25
 */
@Service
public class ProductStockServiceImpl extends ServiceImpl<ProductStockEntityMapper, ProductStockEntity> implements IProductStockService {

    @Override
    public List<ProductStockEntity> listBySkuIds(Collection<String> skuIds) {
        if (CollUtil.isEmpty(skuIds)) {
            return Lists.newArrayListWithCapacity(0);
        }

        return lambdaQuery()
                .in(ProductStockEntity::getSkuId, skuIds)
                .list();
    }

    @Override
    public List<ProductStockEntity> listBySkuIds(Collection<String> skuIds,
                                                 SFunction<ProductStockEntity, ?>... columns) {
        if (CollUtil.isEmpty(skuIds) || Objects.isNull(columns)) {
            return Lists.newArrayListWithCapacity(0);
        }

        return lambdaQuery()
                .select(columns)
                .in(ProductStockEntity::getSkuId, skuIds)
                .list();
    }

    @Override
    public ProductStockEntity get(String userId, String stashName, String skuId) {
        return lambdaQuery()
                .eq(ProductStockEntity::getUserId, userId)
                .eq(ProductStockEntity::getSkuId, skuId)
                .eq(ProductStockEntity::getStashName, stashName)
                .one();
    }
}
